home *** CD-ROM | disk | FTP | other *** search
- Frequently Asked Questions (FAQS);faqs.139
-
-
-
- #!/bin/ksh
- #
- # Permanently remove a product from disk and AIX databases
- #
-
- if [ `whoami` != "root" ] ; then
- echo You must be root to run this script.
- exit 1
- fi
-
- if [ `uname -a | awk '{print $1$4$3}'` != "AIX32" ] ; then
- echo This script only works on AIX 3.2.
- exit 1
- fi
-
- TMP_FREE=`df /tmp | awk '$3 ~ /[0-9]/{print $3}'`
- if [ "$TMP_FREE" -lt 1000 ] ; then
- echo There is not enough room in your /tmp directory.
- echo You need 1000 KB free, and you have only $TMP_FREE KB free.
- echo Either remove some stuff from /tmp, or use chfs to make it bigger.
- exit 1
- fi
-
- ODMDIRS="/etc/objrepos /usr/lib/objrepos /usr/share/lib/objrepos"
- ODMDIR=/usr/lib/objrepos
- export ODMDIR
-
- if [ $# -lt 1 ]
- then
- echo usage: $0 lppname [lppname ...]
- echo lppname is a string compatible with grep, ie "X11" or "PHIGS"
- echo typing $0 PHIGS will remove all LPPs with PHIGS in their name.
- exit 1
- fi
-
- NAMES=$1
- shift
- while [ $# -gt 0 ] ; do
- NAMES="$NAMES|$1"
- shift
- done
- echo "Searching for lpps with egrep \"$NAMES\"...\c"
-
- for ODMDIR in $ODMDIRS ; do
- if [ ! -d $ODMDIR -o ! -w $ODMDIR ] ; then
- echo $ODMDIR is not writeable or is not a directory.
- echo I hope this is because you are a /usr client or diskless.
- echo If you are not a diskless or a /usr client, you should stop.
- echo "Enter y to continue ->\c"
- read answer
- if [ "$answer" != "y" ] ; then
- exit 0
- fi
- fi
- TMP=`odmget lpp | awk -F\" '/name/ {print $2}' | egrep "$NAMES"`
- LPPS=`echo $LPPS $TMP`
- done
-
- if [ "$LPPS" = "" ]
- then
- echo "failed.\nNo LPP with the name $NAMES detected."
- exit 1
- fi
- echo ok.
-
- for ODMDIR in $ODMDIRS ; do
- mkdir -p /tmp/rmlpp/$ODMDIR > /dev/null 2>&1
- done
-
- > /tmp/listOfFilesToRM$$ # truncate temporary file, just in case.
- echo
- echo This script is about to attempt to remove an LPP from your system.
- echo I say attempt, because it could fail. If it fails, you may have
- echo to at least reload the LPP. Use the \"lppchk\" command to make sure
- echo all is well with your system.
- echo
- # Loop through all the LPP names found.
- for LPP in $LPPS
- do
- DESCR=none
- answer=""
-
- # find the LPP ids. They will be different in the three SWVPD databases.
- for ODMDIR in $ODMDIRS ; do
- # get the lpp id for this ODMDIR (yes, they are different)
- LPPID=`odmget -q name=$LPP lpp | grep lpp_id | sed 's/.* = //'`
-
- # did we find the LPP?
- if [ "$DESCR" = "none" -a "$LPPID" != "" ] ; then
- # all the descriptions should be the same
- DESCR=`odmget -q name=$LPP lpp | grep description | sed 's/.* = //'`
- echo "Delete $LPP, $DESCR?"
- echo "y or (n) ->\c"
- read answer
- if [ "$answer" != "y" ] ; then # jump back up to the next LPP name
- continue 2
- fi
- fi
- # if there is no DESCR, then we didn't find the LPP. Weird.
- if [ "$DESCR" = "none" -o "$LPPID" = "" ] ; then
- continue
- fi
- SOMETHING_DONE_FLAG=true
- # Optionally, save the ODM stuff we are about to remove,
- # in case something goes wrong. The problem is it is difficult
- # to determine if something really did fail, since these commands
- # don't return any decent error return codes.
- odmget -q lpp_id=$LPPID history > /tmp/rmlpp/$ODMDIR/$LPP.history
- odmget -q name=$LPP lpp > /tmp/rmlpp/$ODMDIR/$LPP.lpp
- odmget -q lpp_name=$LPP product > /tmp/rmlpp/$ODMDIR/$LPP.product
- # Get the list of files and links to remove later....
- odmget -q lpp_id=$LPPID inventory > /tmp/rmlpp/$ODMDIR/$LPP.inventory
- awk -F\" '/loc/ {print $2}' /tmp/rmlpp/$ODMDIR/$LPP.inventory | \
- sed 's/,/ /g' >> /tmp/listOfFilesToRM$$
- odmdelete -o history -q lpp_id=$LPPID > /dev/null 2>&1
- odmdelete -o lpp -q name=$LPP > /dev/null 2>&1
- odmdelete -o product -q lpp_name=$LPP > /dev/null 2>&1
- odmdelete -o inventory -q lpp_id=$LPPID > /dev/null 2>&1
- done
- done
-
- if [ "$SOMETHING_DONE_FLAG" = "true" ] ; then
-
- echo ODM work is done. Now, time to delete files....
-
- # This could be catastrophic if there is a problem. For example,
- # if the ODM database for an application had / as one of its files.
- # You be the judge. Here's your rope....
- cat /tmp/listOfFilesToRM$$ | sort -r | uniq | xargs rm -rf
-
- rm -rf /tmp/listOfFilesToRM$$
- echo done.
- fi
-
- # take this line out if you want to save your ODM saved files.
- rm -rf /tmp/rmlpp
-
- exit 0
-
-
- 1.25 *My named dies frequently, why?
-
- Running on 3.2, named dies frequently on network's primary name server.
-
- From: jpe@ee.egr.duke.edu (John P. Eisenmenger)
-
- Try the following:
-
- stopsrc -s named # stop running named
- setenv MALLOCTYPE 3.1 # use 3.1 memory allocation algorithm
- /etc/named ... # don't use smit to start named
-
- You might be able to use startsrc/smit after setting MALLOCTYPE and get
- the same effect, but I'm not sure.
-
- [According to John, the problem is malloc() in the named code. He
- also suggests using Berkeley's bind, which he has ported and can be
- ftp'ed from ftp.egr.duke.edu, /archives/network/bind-4.8.3.tar.Z. -ed]
-
-
- 1.26: How do I trace ethernet packets on an AIX system?
- From: afx@muc.ibm.de (Andreas Siegert)
-
- Do the following:
-
- iptrace -i en0 /tmp/ipt
-
- The iptrace backgrounds. Find its process id and kill it when you are
- ready. Then run
-
- ipreport -rns /tmp/ipt >/tmp/ipr
-
- and look at the output. The current version of Info does not document
- the r, n and s options but they are quite useful for layering the output.
-
- ______________________________________________________________________________
- 2.00: C/C++
-
- Contrary to many people's belief, the C environment on the RS/6000 is
- not very special. The C compiler has quite a number of options that can
- be used to control how it works, which "dialect" of C it compiles, how
- it interprets certain language constructs, etc. InfoExplorer includes a
- Users' Guide and a Reference Manual.
-
- The compiler can be invoked with either xlc to invoke it in ANSI mode
- and cc to invoke it in RT (i.e. IBM 6150 with AIX 2) compatible mode.
- The default options for each mode are set in the /etc/xlc.cfg file, and
- you can actually add another stanza and create a link to the /bin/xlc
- executable.
-
- The file /usr/lpp/xlc/bin/README.xlc has information about the C
- compiler, and the file /usr/lpp/bos/bsdport contains useful information,
- in particular for users used to BSD.
-
- The file /etc/xlc.cfg also shows the symbol _IBMR2 that is predefined,
- and therefore can be used for #ifdef'ing RS/6000 specific code.
-
-
- 2.01: I cannot make alloca work
-
- A famous routine, in particular in GNU context, is the allocation
- routine alloca(). Alloca allocates memory in such a way that it is
- automatically free'd when the block is exited. Most implementations
- does this by adjusting the stack pointer. Since not all C environments
- can support it, its use is discouraged, but it is included in the xlc
- compiler. In order to make the compiler aware that you intend to use
- alloca, you must put the line
-
- #pragma alloca
-
- before any other statements in the C source module(s) where alloca is
- called. If you don't do this, xlc will not recognize alloca as anything
- special, and you will get errors during linking.
-
- In earlier releases of the C compiler, alloca did not work well with the
- optimizer turned on (-O flag), but this problem is solved now. The fix
- was probably in release 1.1.3 of xlc.obj, it is for sure in 1.1.5.
-
-
- 2.02: How do I compile my BSD programs?
-
- The file /usr/lpp/bos/bsdport contains information on how to port
- programs written for BSD to AIX 3.1. The contents of this file can
- actually be very useful for others as well.
-
- A quick cc command for most "standard" BSD programs is:
-
- $ cc -D_BSD -D_BSD_INCLUDES -o [loadfile] [sourcefile.c] -lbsd
-
- If your software has system calls predefined with no prototype
- parameters, also use the -D_NO_PROTO flag.
-
-
- 2.03: Isn't the linker different from what I am used to?
-
- Yes. It is not at all like what you are used to:
-
- - The order of objects and libraries is normally _not_ important. The
- linker reads _all_ objects including those from libraries into memory
- and does the actual linking in one go. Even if you need to put a
- library of your own twice on the ld command line on other systems, it
- is not needed on the RS/6000 - doing so will even make your linking slower.
-
- - One of the features of the linker is that it will replace an object in
- an executable with a new version of the same object:
-
- $ cc -o prog prog1.o prog2.o prog3.o # make prog
- $ cc -c prog2.c # recompile prog2.c
- $ cc -o prog.new prog2.o prog # make prog.new from prog
- # by replacing prog2.o
-
- - The standard C library /lib/libc.a is linked shared, which means that
- the actual code is not linked into your program, but is loaded only
- once and linked dynamically during loading of your program.
-
- - The ld program actually calls the binder in /usr/lib/bind, and you can
- give ld special options to get details about the invocation of the
- binder. These are found on the ld man page or in InfoExplorer.
-
- - If your program normally links using a number of libraries (.a files),
- you can 'prelink' each of these into an object, which will make your
- final linking faster. E.g. do:
-
- $ cc -c prog1.c prog2.c prog3.c
- $ ar cv libprog.a prog1.o prog2.o prog3.o
- $ ld -r -o libprog.o libprog.a
- $ cc -o someprog someprog.c libprog.o
-
- This will solve all internal references between prog1.o, prog2.o and
- prog3.o and save this in libprog.o Then using libprog.o to link your
- program instead of libprog.a will increase linking speed, and even if
- someprog.c only uses, say prog1.o and prog2.o, only those two modules
- will be in your final program. This is also due to the fact that the
- binder can handle single objects inside one object module as noted above.
-
- If you are using an -lprog option (for libprog.a) above, and still want
- to be able to do so, you should name the prelinked object with a
- standard library name, e.g. libprogP.a (P identifying a prelinked
- object), that can be specified by -lprogP. You cannot use the archiver
- (ar) on such an object.
-
- You should also have a look at section 3.01 of this article, in
- particular if you have mixed Fortran/C programs.
-
-
- 2.04: How do I link my program with a non-shared /lib/libc.a?
-
- cc -o prog -bnoso -bI:/lib/syscalls.exp obj1.o obj2.o obj3.o
-
- will do that for a program consisting of the three objects obj1.o, etc.
-
-
- 2.05: How do I make my own shared library?
-
- To make your own shared object or library of shared objects, you should
- know that a shared object cannot have undefined symbols. Thus, if your
- code uses any externals from /lib/libc.a, the latter MUST be linked with
- your code to make a shared object. Likewise, you cannot split your code
- into more than one shared object if externals in one object refer to
- another one.
-
- Assume you have one file, sub1.c, containing a routine with no external
- references, and another one, sub2.c, calling stuff in /lib/libc.a. You
- will also need two export files, sub1.exp, sub2.exp. Read the example
- below together with the examples on the ld man page.
-
- ---- sub1.c ----------------------------------------------------------
- int addint(int a, int b)
- {
- return a + b;
- }
- ---- sub2.c ----------------------------------------------------------
- #include <stdio.h>
-
- void printint(int a)
- {
- printf("The integer is: %d\n", a);
- }
- ---- sub1.exp ----------------------------------------------------------
- #!
- addint
- ---- sub2.exp ----------------------------------------------------------
- #!
- printint
- ---- usesub.c ----------------------------------------------------------
- main()
- {
- printint( addint(5,8) );
- }
- ---------------------------------------------------------------
-
- The following commands will build your libshr.a, and compile/link the
- program usesub to use it. Note that you need the ld option -lc for
- sub2shr.o since it calls printf from /lib/libc.a.
-
- $ cc -c sub1.c
- $ ld -o sub1shr.o sub1.o -bE:sub1.exp -bM:SRE -T512 -H512
- $ cc -c sub2.c
- $ ld -o sub2shr.o sub2.o -bE:sub2.exp -bM:SRE -T512 -H512 -lc
- $ ar r libshr.a sub1shr.o sub2shr.o
- $ cc -o usesub usesub.c -L: libshr.a
- $ usesub
- The integer is: 13
- $
-
-
- 2.06: Linking my program fails with strange errors. Why?
-
- Very simple, the linker (actually called the binder), cannot get the
- memory it needs, either because your ulimits are too low or because you
- don't have sufficient paging space. Since the linker is quite different
- from normal Unix linkers and actually does much more than these, it also
- uses a lot of virtual memory. It is not unusual to need 10000 pages (of
- 4k) or more to execute a fairly complex linking.
-
- If you get 'BUMP error', either ulimits or paging is too low, if you get
- 'Binder killed by signal 9' your paging is too low.
-
- First, check your memory and data ulimits; in korn shell 'ulimit -a' will
- show all limits and 'ulimit -m 99999' and 'ulimit -d 99999' will
- increase the maximum memory and data respectively to some high values.
- If this was not your problem, you don't have enough paging space.
-
- If you will or can not increase your paging space, you could try this:
-
- - Do you duplicate libraries on the ld command line? That is never
- necessary.
-
- - Do more users link simultaneously? Try having only one linking going
- on at any time.
-
- - Do a partwise linking, i.e. you link some objects/libraries with the
- -r option to allow the temporary output to have unresolved references,
- then link with the rest of your objects/libraries. This can be split
- up as much as you want, and will make each step use less virtual memory.
-
- If you follow this scheme, only adding one object or archive at a
- time, you will actually emulate the behavior of other Unix linkers.
-
- If you decide to add more paging space, you should consider adding a new
- paging space on a second hard disk, as opposed to just increasing the
- existing one. Doing the latter could make you run out of free space on
- your first harddisk. It is more involved to shrink a paging space
- but easier to delete one.
-
- --
- Luis Basto
- Computer Sciences Corporation
- Internet: basto@cactus.org
- Usenet: cs.utexas.edu!mavrick!luis
- Xref: bloom-picayune.mit.edu comp.unix.aix:19872 news.answers:4575
- Path: bloom-picayune.mit.edu!enterpoop.mit.edu!usc!wupost!cs.utexas.edu!mavrick!basto@cactus.org
- From: basto@cactus.org (Luis Basto)
- Newsgroups: comp.unix.aix,news.answers
- Subject: AIX Frequently Asked Questions (Part 2 of 2)
- Summary: This posting contains a list of Frequently Asked Questions
- and their answers about AIX, IBM's version of Unix.
- Keywords: AIX RS/6000 questions answers
- Message-ID: <1070@mavrick.UUCP>
- Date: 14 Dec 92 07:22:02 GMT
- Expires: 15 Jan 93 01:23:45 GMT
- Sender: luis@mavrick.UUCP
- Reply-To: basto@cactus.org (Luis Basto)
- Followup-To: comp.unix.aix
- Lines: 1156
- Approved: news-answers-request@MIT.Edu
-
- Archive-name: aix-faq/part2
- Last-modified: Dec 12, 1992
- Version: 2.0
-
-
- Version: $Id: aix.faq,v 2.0 12/12/92 basto $
-
- Frequently Asked Questions to AIX 3.x and IBM RS/6000
- _____________________________________________________
-
- 2.07: What's with malloc()?
-
- malloc() uses a late allocation algorithm based on 4.3 BSD's malloc()
- for speed. This lets you allocate very large sparse memory spaces,
- since the pages are not actually allocated until they are touched for
- the first time. Unfortunately, it doesn't die gracefully in the face of
- loss of available memory. See the "Paging Space Overview" under
- InfoExplorer, and see the notes on the linker in this document for an
- example of an ungraceful death.
-
- If you want your program to get notified when running out of memory, you
- should handle the SIGDANGER signal. The default is to ignore it.
- SIGDANGER is sent to all processes when paging space gets low, and if
- paging space gets even lower, processes with the highest paging space
- usage are sent the SIGKILL signal.
-
- malloc() is substantially different in 3.2, allocating memory more
- tightly. If you have problems running re-compiled programs on 3.2, try
- compiling them with MALLOCTYPE=3.1.
-
-
- 2.08: Why does xlc complain about 'extern char *strcpy()'
-
- The header <string.h> has a strcpy macro that expands strcpy(x,y) to
- __strcpy(x,y), and the latter is then used by the compiler to generate
- inline code for strcpy. Because of the macro, your extern declaration
- contains an invalid macro expansion. The real cure is to remove your
- extern declaration but adding -U__STR__ to your xlc will also do the trick.
-
-
- 2.09: Why do I get 'Parameter list cannot contain fewer ....'
-
- This is the same as above.
-
-
- 2.10: Why does xlc complain about '(sometype *)somepointer = something'
-
- Software that is developed using GNUC may have this construct. However,
- standard C does not permit casts to be lvalues, so you will need to
- change the cast and move it to the right side of the assignment. If you
- compile with 'cc', removing the cast completely will give you a warning,
- 'xlc' will give you an error (provided somepointer and something are of
- different types - but else, why would the cast be there in the first place?)
-
-
- 2.11: Some more common errors
-
- Here are a few other common errors with xlc:
-
- 305 | switch((((np)->navigation_type) ? (*((np)->navigation_type)) :
- ((void *)0)))
- .a...........
- a - 1506-226: (S) The second and third operands of the conditional
- operator must be of the same type.
-
- The reason for this is that xlc defines NULL as (void *)0, and it does
- not allow two different types as the second and third operand of ?:.
- The second argument above is not a pointer and the code used NULL
- incorrectly as a scalar. NULL is a nil pointer constant in ANSI C and
- in some traditional compilers.
-
- You should change NULL in the third argument above to an integer 0.
-
-
- 2.12: Can the compiler generate assembler code?
-
- The traditional -S option is not supported by the XLC compiler, and
- there is in fact no way to make the compiler generate machine readable
- assembler code. The option -qlist will generate a human readable one in
- the .lst file.
-
-
- 2.13: Curses
-
- Curses based applications should be linked with -lcurses and _not_ with
- -ltermlib. It has also been reported that some problems with curses are
- avoided if your application is compiled with -DNLS.
-
- Peter Jeffe <peter@ski.austin.ibm.com> also notes:
-
- >the escape sequences for cursor and function keys are *sometimes*
- >treated as several characters: eg. the getch() - call does not return
- >KEY_UP but 'ESC [ C.'
-
- You're correct in your analysis: this has to do with the timing of the
- escape sequence as it arrives from the net. There is an environment
- variable called ESCDELAY that can change the fudge factor used to decide
- when an escape is just an escape. The default value is 500; boosting
- this a bit should solve your problems.
-
- Further on the matter of curses, I've received the comments below
- concerning extended curses:
-
- From: Christopher Carlyle O'Callaghan <asdfjkl@wam.umd.edu>
-
- 1) The sample program in User Interface Programming Concepts, page 7-13
- is WRONG. Here is the correct use of panes and panels. (This is
- one of the IBM manuals that comes with the RS/6000)
-
- #include <cur01.h>
- #include <cur05.h>
-
- main()
- {
- PANE *A, *B, *C, *D, *E, *F, *G, *H;
- PANEL *P;
-
- initscr();
-
- A = ecbpns (24, 79, NULL, NULL, 0, 2500, Pdivszp, Pbordry, NULL, NULL);
-
- D = ecbpns (24, 79, NULL, NULL, 0, 0, Pdivszf, Pbordry, NULL, NULL);
- E = ecbpns (24, 79, D, NULL, 0, 0, Pdivszf, Pbordry, NULL, NULL);
-
- B = ecbpns (24, 79, A, D, Pdivtyh, 3000, Pdivszp, Pbordry, NULL, NULL);
-
- F = ecbpns (24, 79, NULL, NULL, 0, 0, Pdivszf, Pbordry, NULL, NULL);
- G = ecbpns (24, 79, F, NULL, 0, 5000, Pdivszp, Pbordry, NULL, NULL);
- H = ecbpns (24, 79, G, NULL, 0, 3000, Pdivszp, Pbordry, NULL, NULL);
-
- C: = ecbpns (24, 79, B, F, Pdivtyh, 0, Pdivszf, Pbordry, NULL, NULL);
-
- P = ecbpls (24, 79, 0, 0, "MAIN PANEL", Pdivtyv, Pbordry, A);
-
- ecdvpl (P);
- ecdfpl (P, FALSE);
- ecshpl (P);
- ecrfpl (P);
- endwin();
- }
-
- 2) DO NOT include <curses.h> and any other <cur0x.h> file together.
- You will get a bunch of redefined statements.
-
- 3) There is a CURSES and EXTENDED CURSES stuff. Use only one or the
- other. If the manual says that they're backwards compatible or some
- other indication that you can use CURSES routines with EXTENDED,
- don't believe it. To use CURSES you need to include <curses.h> and
- you can't (see above).
-
- 4) If you use -lcur and -lcurses in the same link command, you will get
- Memory fault (core dump) error... YOU CANNOT use both of them at the
- same time. -lcur is for extended curses, -lcurses is for regular curses.
-
- 5) When creating PANEs, when you supply a value (other than 0) for the
- 'ds' parameter and use Pdivszf value for the 'du' parameter, the 'ds'
- will be ignored (the sample program on page 7-13 in User Interface
- Programming Concepts is wrong.) For reasons as yet undetermined,
- Pdivszc doesn't seem to work (or at least I can't figure out how to
- use it.)
-
- 6) If you're running into bugs and can't figure out what is happening,
- try the following:
- include -qextchk -g in your compile line
- -qextchk will check to make sure you're passing the right number of
- parameters to the procedures
- -g will allow you to use the inline debugger on Unix/AIX.
- to use the debugger after you compiled it,
- type: dbx <fn>
- the command 'help' will give you all of the possible commands to
- use in the debugger... have fun... :)
-
- 7) Do not use 80 as the number of columns if you're gonna use the whole
- screen. The lower right corner will get erased. Use 79 instead.
-
- 8) If you create a panel, you must create at least 1 pane, otherwise you
- will get a Memory fault (core dump).
-
- 9) When creating a panel, if you don't have a border around it, any title
- you want will not show up.
-
- 10) to make the screen scroll down:
- wmove (win, 0, 0);
- winsertln (win)
-
- 11) delwin(win) DOESN'T WORK IN EXTENDED WINDOWS.
-
- Anyway.. to make it appear as if a window is deleted, you need to do
- the following:
- for every window that you want to appear on the screen
- touchwin(win)
- wrefresh(win)
-
- you must make sure that you do it in the exact same order as you put
- them on the screen (i.e., if you called newwin with A, then C, then B,
- then you must do the loop with A, then C, then B, otherwise you won't
- get the same screen back). The best thing to do is to put them into
- an array and keep track the of last window index.
-
- 12) mvwin(win, line, col) implies that it is only used for viewports and
- subwindows... It can also be used for the actual windows themselves.
-
- 13) If you specify the attribute of a window using wcolorout(win), any
- subsequent calls to chgat(numchars, mode) or any of it's relatives
- will not work. (or at least they get very picky...)
-
-
- 2.14: How do I speed up linking
-
- Please refer to sections 2.03 and 2.06 above.
-
-
- 2.15: What is deadbeef?
-
- When running the debugger (dbx), you may have wondered what the
- 'deadbeef' is you occasionally see in registers. Do note, that
- 0xdeadbeef is a hexadecimal number that also happens to be some kind
- of word (the RS/6000 was built in Texas!), and this hexadecimal number
- is simply put into unused registers at some time, probably during
- program startup.
-
- _____________________________________________________________________________
- 3.00: Fortran and other compilers
-
- This section covers Fortran, Pascal, Ada, etc. On fortran, there seem
- to have been some problems with floating point handling, in particular
- floating exceptions.
-
-
- 3.01: I have problems mixing fortran and C code, why?
-
- A few routines (the most famous one is getenv) exist in both the fortran
- and the C library but with different parameters. You can therefore not
- have a mixed program that call getenv from both C and fortran code.
- When linking a mixed program calling getenv from either, be sure to
- specify the correct library first on your command line. If your main
- program is fortran and you call getenv from a C routine, you must
- therefore add -lc to the xlf command line for linking.
-
- If you want to call getenv from both C and fortran code in a mixed
- program, you need to compile all the fortran code with the -qextname
- option. This appends an underscore to all fortran external names and
- ensures that no confusion occurs with default C libraries. Of course an
- underscore should be added by hand in the C code to the name of all
- routines which are called form fortran and to all calls to fortran
- routines. If you do that, fortran will call something which appears to
- C as getenv_ and there will be no confusion.
-
-
- 3.02: How do I statically bind fortran libraries and dynamically
- bind C libraries?
- From: amaranth@vela.acs.oakland.edu (Paul Amaranth)
-
- [ Editor's note: Part of this is also discussed above under the C compiler
- discussions, but I felt it was so valuable that I have left it all in.
- I've done some minor editing, mostly typographical. ]
-
- The linker and binder are rather versatile programs, but it is not
- always clear how to make them do what you want them to. In particular,
- there are times when you do not want to use shared libraries, but
- rather, staticly bind the required routines into your object. Or, you
- may need to use two version of the same routine (eg, Fortran & C). Here
- are the results of my recent experiments. I would like to thank Daniel
- Premer and Brad Hollowbush, my SE, for hints. Any mistakes or omissions
- are my own and I have tended to interchange the terms "linker" and
- "binder". These experiments were performed on AIX 3.1.2. Most of this
- should be applicable to later upgrades of 3.1.
-
- 1) I have some C programs, I want to bind in the runtime routines. How
- do I do this? [Mentioned in section 2.04 of this article as well, ed.]
-
- You can put the -bnso binder command on the link line. You should
- also include the -bI:/lib/syscalls.exp control argument:
-
- $ cc *.o -bnso -bI:/lib/syscalls.exp -o foo
-
- This will magically do everything you need. Note that this will bind
- _all_ required routines in. The -bI argument tells the linker that
- these entry points will be resolved dynamically at runtime (these are
- system calls). If you omit this you will get lots of unresolved
- reference messages.
-
- 2) I want to staticly bind in the Fortran runtime so a) my customers do
- not need to buy it and b) I don't have to worry about the runtime
- changing on a new release. Can I use the two binder arguments in
- 1) to do this?
-
- You should be able to do so, but, at least under 3002, if you do
- you will get a linker error referencing getenv. In addition, there
- are a number of potential conflicts between Fortran and C routines.
- The easy way just does not work. See the section on
- 2 stage linking for C and Fortran on how to do this. The getenv
- problem is a mess, see the section on Comments & Caveats for more.
-
- 3) I have a mixture of C and Fortran routines, how can I make sure
- that the C routines reference the C getenv, while the Fortran routines
- reference the Fortran getenv (which has different parameters and, if
- called mistakenly by a C routine results in a segmentation fault)?
-
- You can't. Only one symbol definition is allowed, and it will be the
- _first_ definition on the _last_ link. Here is the quote from the
- ld info file:
-
- In this version of ld, the first definition of each symbol in
- the link takes precedence and is used even if the first reference
- follows the definition.
-
- The only way I can possibly think of to do this is extremely messy:
- Make the C and Fortran routines separate modules. Staticly bind them
- with their libraries. Have them dynamicly call each other. ech.
- I haven't tried this, however.
-
- If you want to bind everything together, write yourself an interface
- in one language to use the other's routine. I did this with getenv
- and it works tolerably well.
-
- 4) I have C and Fortran routines. I want to bind in the xlf library, while
- letting the rest of the libraries be shared. How do I do this?
-
- You need to do a 2 stage link. In the first stage, you bind in the
- xlf library routines, creating an intermediate object file. The
- second stage resolves the remaining references to the shared libraries.
-